package com.dotools.toutiaolibrary;

import android.app.Activity;

import com.bykv.vk.openvk.TTAdLoadType;
import com.bykv.vk.openvk.TTFullVideoObject;
import com.bykv.vk.openvk.TTVfConstant;
import com.bykv.vk.openvk.TTVfManager;
import com.bykv.vk.openvk.TTVfNative;
import com.bykv.vk.openvk.VfSlot;

import api.ttfullvideo.FullVideo_API_TT;

public class TT_FullVideo extends FullVideo_API_TT {
    private TTVfNative mTTAdNative;
    private TTFullVideoObject mTTFullScreenVideoOb;

    @Override
    public void LoadTTFullVideo(final Activity context, String appid, String adposid, int count, int downloadMode, boolean isDebug, int orientation, final TTFullVideoListener listener) {
        if (appid != null) {
            if (appid.trim().equals("")) {
                return;
            }
        } else {
            return;
        }
        TTVfManager manager = TTManagerHolder.get();
        if (manager != null) {
            mTTAdNative = manager.createVfNative(context.getApplicationContext());
            //step4:创建广告请求参数AdSlot,具体参数含义参考文档
            VfSlot adSlot = new VfSlot.Builder()
                    .setCodeId(adposid)
                    .setSupportDeepLink(true)
                    .setAdLoadType(TTAdLoadType.LOAD)
                    .setOrientation(orientation) //必填参数，期望视频的播放方向：TTAdConstant.HORIZONTAL 或 TTAdConstant.VERTICAL
                    .build();
            if (downloadMode == 1) {
                adSlot.setDownloadType(TTVfConstant.DOWNLOAD_TYPE_POPUP);
            }
            //step5:请求广告
            mTTAdNative.loadFullVideoVs(adSlot, new TTVfNative.FullScreenVideoAdListener() {


                @Override
                public void onError(int code, String message) {
                    listener.onError(code, message);
                }

                @Override
                public void onFullVideoVsLoad(TTFullVideoObject ttFullVideoObject) {
                    mTTFullScreenVideoOb = ttFullVideoObject;
                    mTTFullScreenVideoOb.setFullScreenVideoAdInteractionListener(new TTFullVideoObject.FullVideoVsInteractionListener() {

                        @Override
                        public void onShow() {
                            listener.onObShow();
                        }

                        @Override
                        public void onVideoBarClick() {
                            listener.onObVideoBarClick();
                        }

                        @Override
                        public void onClose() {
                            listener.onObClose();
                        }

                        @Override
                        public void onVideoComplete() {
                            listener.onVideoComplete();
                        }

                        @Override
                        public void onSkippedVideo() {
                            listener.onSkippedVideo();
                        }
                    });
                }

                @Override
                public void onFullVideoCached() {
                }

                @Override
                public void onFullVideoCached(TTFullVideoObject ttFullVideoObject) {
                    ttFullVideoObject.showFullVideoVs(context);
                }
            });
        } else {
            listener.onError(666, "TTVfManager is null  可能原因sdk未初始化成功");
        }
    }

    @Override
    public void onDestroy() {
        mTTFullScreenVideoOb = null;
    }
}
